﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace UserInterface
{
    public partial class Statistics : Form
    {
        Crossing[] cr;
        int[] index = new int[7];
        List<Lane> allLanes = new List<Lane>();
        List<Pedestrian> pedestrians = new List<Pedestrian>();
        public Statistics(Map mp)
        {
            InitializeComponent();
            cr = mp.GetAllCrossings();
            for (int i=0, j=0; i<7; i++)
            {
                if (mp.GetAllCrossings()[i] != null)
                {
                    this.comboBox1.Items.Add(i +" "+cr[i].GetType());
                    index[j] = i;
                    j++;
                }
            }
          }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            int crossingIndex = index[this.comboBox1.SelectedIndex];
            this.allLanes = cr[index[this.comboBox1.SelectedIndex]].getLaneStatistics();
            
            this.pedestrians = cr[crossingIndex].getPedestrians();
            
            this.listBox3.Items.Clear();
            if (this.pedestrians != null)
            {
                this.listBox3.Items.Add("Pedestrians");
                this.listBox3.Items.Add("Departure\tDestination");
                this.listBox3.Items.Add("");
                for (int i = 0; i < this.pedestrians.Count; i++)
                {
                    string dest = pedestrians[i].destination == null ? "None" : pedestrians[i].destination.LaneId.ToString();
                    this.listBox3.Items.Add(this.pedestrians[i].departure.LaneId + " " + dest);
                }
            }
            else
                this.listBox3.Items.Add("Pedestrians are not available");

            this.listBox1.Items.Clear();
            this.listBox1.Items.Add("Lane\t Fluxation\t Direction\t Has Neighbours \tCars Generated \t CarsPassed");
            this.listBox1.Items.Add("");
            this.listBox2.Items.Clear();
            this.listBox2.Items.Add("Cars in Lane\tMAX no of Cars");
            this.listBox2.Items.Add("");
            
            for (int i = 0; i < allLanes.Count; i++)
            {
                this.listBox1.Items.Add(allLanes[i].LaneId + "\t" + allLanes[i].flux.ToString() + "\t" + allLanes[i].direction+"\t"+allLanes[i].HasNeighbours().ToString()+"\t\tNum\tNum");
                this.listBox2.Items.Add("\t"+allLanes[i].NumberOfCars+" \t" +allLanes[i].MAXCARS);
            }
            
            
            //this.listBox2.Items.Add(cr[index[this.comboBox1.SelectedIndex]].GetHashCode());
        }

        private void About_Load(object sender, EventArgs e)
        {

        }

    }
}
